function Room(){
	this.publicBlogs=new Array();
	this.n=0;
	this.localBlog;
	this.map=null;
	this.adapter = new ClientAdapter("/coupling/");
	this.adapter.joinSession("prueba");
	this.adapter.start(500);
	this.couple();
}

Room.prototype.getPublicBlogs = function(){
	return this.publicBlogs;
};

Room.prototype.setPublicBlogs = function(blogs){
	this.publicBlogs=blogs;
};

Room.prototype.getMap = function(){
	return this.map;
};

Room.prototype.setMap = function(map){
	this.map=map;
};

Room.prototype.getNewId = function(){
	return Math.floor((Math.random()*100000)+1)+'_'+this.adapter.clientId;
};

Room.prototype.addBlog = function(lat,lng){
	var id=this.getNewId();
	var icon='https://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=|0000F0|';
	var latlng = new google.maps.LatLng(lat,lng);
	var marker = new google.maps.Marker({
		position: latlng, 
		title: id,
		draggable: true,
		icon: icon,
		map: this.map
	});
	this.localBlog=new Blog(marker,id);
	google.maps.event.addListener(marker,'click', function () {
		$("#blogId").val(marker.getTitle());
		$("#buttonD").click();
		$("#listComments").hide();
	});
};

Room.prototype.publishBlog = function(blogId){
	this.localBlog.marker.setVisible(false);
	$("#buttonD").click();
	this.publish(blogId,this.localBlog.marker.getPosition().lat(),
			this.localBlog.marker.getPosition().lng(),
			$("#title").val(), $("#description").val());
};

Room.prototype.publish = function(blogId,lat,lng,title,description){
	var latlng = new google.maps.LatLng(lat,lng);
	var marker = new google.maps.Marker({
		position: latlng, 
		title: blogId,
		draggable: false,
		map: this.map
	});
	this.publicBlogs[this.n++]=new Blog(marker,blogId);
	google.maps.event.addListener(marker,'click', function () {
		$("#blogId").val(marker.getTitle());
		$("#title").val(title);
		$("#description").val(description);
		$("#listComments").show();
		$("#buttonD").click();
		
	});
};

Room.prototype.addCommentRoom = function(blogId,body){
	for(var i=0;i<this.n;i++){
		if(this.publicBlogs[i].id==blogId){
			this.publicBlogs[i].addComment(this.adapter.clientId,body);
			break;
		}			
	}
};
Room.prototype.couple=function(){
	this.adapter.coupleObject("room",this,{
		messageType:"EVENT",
		explicitMapping:["publish","addCommentRoom"]
	});
};